// conf
package etc

import (
	"log"
	"swim/util/config"
)

type SwImConfig struct {
	ServerHost          string //主机绑定IP
	ServerPort          int    //主机绑定端口
	InnerIp             string //服务器内部IP（主要用于集群）
	MaxClient           int    //最大客户数
	MaxServiceUser      int    //最大客服人员数目
	OfflineMsgUrl       string //离线留言链接
	OneIpMax            int    //一个Ip最大客户端数目
	GetFileUrl          string //取得上传文件的路径
	MaxUploadSize       int64  //最大上传文件长度
	UploadFilePath      string //上传文件的路径
	CustomerUrl         string //客户管理URL
	AddCustomerUrl      string //增加客户URL
	OfflineMsgMangerUrl string //留言管理url
	MaxMsgPoolSize      int    //最大消息条数
}
type DBconfig struct {
	DbType  string //数据库类型
	Uid     string //用户名
	Pwd     string //密码
	Host    string //数据库主机名
	Port    int    //数据库端口
	Dbname  string //数据库名
	MaxConn int    //连接池中最大连接数量
}
type RedisConfig struct {
	Host string //主机名
	Port int    //端口
	Pwd  string //密码
}

var (
	DBconfiger    *DBconfig
	RedisConfiger *RedisConfig
	SwImConfiger  *SwImConfig
)

func init() {
	loadConfig()
}

func loadConfig() {
	iniconf, err := config.NewConfig("ini", ConfigName)
	if err != nil {
		log.Fatal(err)
		return
	}

	DBconfiger = &DBconfig{
		DbType:  iniconf.DefaultString("database::dbtype", ""),
		Host:    iniconf.DefaultString("database::host", ""),
		Port:    iniconf.DefaultInt("database::port", 3306),
		Dbname:  iniconf.DefaultString("database::dbname", DbName),
		Uid:     iniconf.DefaultString("database::uid", ""),
		Pwd:     iniconf.DefaultString("database::pwd", ""),
		MaxConn: iniconf.DefaultInt("database::maxonn", 200),
	}
	RedisConfiger = &RedisConfig{
		Host: iniconf.DefaultString("redis::host", ""),
		Port: iniconf.DefaultInt("redis::port", 6379),
		Pwd:  iniconf.DefaultString("redis::pwd", ""),
	}
	SwImConfiger = &SwImConfig{
		ServerHost:          iniconf.DefaultString("swim::serverhost", ""),
		ServerPort:          iniconf.DefaultInt("swim::serverport", 8080),
		InnerIp:             iniconf.DefaultString("swim::innerip", ""),
		OfflineMsgUrl:       iniconf.DefaultString("swim::OfflineMsgUrl", ""),
		MaxClient:           iniconf.DefaultInt("swim::maxclient", 100),
		MaxServiceUser:      iniconf.DefaultInt("swim::MaxServiceUser", 100),
		OneIpMax:            iniconf.DefaultInt("swim::OneIpMax", 5),
		GetFileUrl:          iniconf.DefaultString("swim::GetFileUrl", ""),
		CustomerUrl:         iniconf.DefaultString("swim::CustomerUrl", ""),
		AddCustomerUrl:      iniconf.DefaultString("swim::AddCustomerUrl", ""),
		OfflineMsgMangerUrl: iniconf.DefaultString("swim::OfflineMsgMangerUrl", ""),
		UploadFilePath:      iniconf.DefaultString("swim::UploadFilePath", "./down/"),
		MaxUploadSize:       iniconf.DefaultInt64("swim::MaxUploadSize", 8*M),
		MaxMsgPoolSize:      iniconf.DefaultInt("swim::MaxMsgPoolSize", S_MAX_MSG_POOL_SIZE),
	}
}
